import { defineStore } from "pinia"
import type { MessageStoreType } from './interface/messageType'
// api
import { reqGetMessageList } from '@/api/message/index'
// api ts类型
import type { MessageListResponseData } from '@/api/message/type'
// pinia
import { useUserInfoStore } from "@/store/modules/user"
const userInfoStore = useUserInfoStore()

export const useMessageStore = defineStore('messageStore', {
    state: (): MessageStoreType => {
        return {
            messageChatList: [], // 消息详情列表
            messageList: [], // 左侧消息大列表
        }
    },
    actions: {
        // 获取聊天列表数据
        async getMessageList() {
            let res: MessageListResponseData = await reqGetMessageList(userInfoStore.userInfo._id)
            if (res.status === 200) {
                this.messageList = res.data
            }
        }
    }
})